package org.ktjy.springbootredis.service;

import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.io.Serializable;

@Service("redisService")
public class RedisService {
    private static final Logger log = LoggerFactory.getLogger(RedisService.class);
    @Resource
    private RedisTemplate redisTemplate;

    private Logger logger = LoggerFactory.getLogger(RedisService.class);
    public boolean set(String key, String value){
        boolean result = false;
        try {
            ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
            operations.set(key, value);
            return true;
        } catch (Exception e) {
            logger.error("set error: key{}, value{}", key, value, e);
        }
        return result;
    }

    @Cacheable(value = "user", keyGenerator = "keyGenerator")
    public void getUser(Long usrId){
//        return userMapper.selectById(usrId);
    }
}
